//
//  String+ZZTools.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/6.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit


extension String {
    
    func isMobileNumber() -> Bool {
        
        let MOBILE = "^1[34578]\\d{9}$"
        let CM = "^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$"
        let CU = "^1(3[0-2]|5[256]|8[56])\\d{8}$"
        let CT = "^1((83|47|33|53|8[09])[0-9]|349)\\d{7}$"
        
        let regextestMobile = NSPredicate(format: "SELF MATCHES %@", MOBILE)
        let regextestCM = NSPredicate(format: "SELF MATCHES %@", CM)
        let regextestCU = NSPredicate(format: "SELF MATCHES %@", CU)
        let regextestCT = NSPredicate(format: "SELF MATCHES %@", CT)
        
        if regextestMobile.evaluate(with: self)
        || regextestCM.evaluate(with: self)
        || regextestCT.evaluate(with: self)
        || regextestCU.evaluate(with: self) {
            return true
        } else {
            return false
        }
    }
    
    func isNumber() -> Bool {
        let regex = "^[0-9]+$"
        let pred = NSPredicate(format: "SELF MATCHES %@", regex)
        
        return pred.evaluate(with: self)
    }
}
